<template>
  <el-container>
    <el-header>
      <div>
        <img src="../assets/ball_icon.png" />
        <span>管理后台</span>
      </div>
      <el-dropdown @command="handleCommand">
        <el-button>
          <span class="w-font"
            ><span class="f-right">欢迎您!</span><br />{{
              admin.roleName
            }}</span
          ><i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="edit">信息修改</el-dropdown-item>
          <el-dropdown-item command="logout">退出登陆</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <!-- <el-button type="info" @click="logout">退出</el-button> -->
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse()">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409BFF"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="activePath"
        >
          <!-- 一级菜单  -->
          <el-submenu index="1">
            <!-- 一级菜单模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="el-icon-menu"></i>
              <!-- 文本 -->
              <span>用户管理</span>
            </template>
            <el-menu-item index="users">
              <i class="el-icon-s-tools"></i>
              <span>用户管理</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>权限管理</span>
            </template>
            <el-menu-item index="admin">
              <i class="el-icon-s-tools"></i>
              <span>后台用户管理</span>
            </el-menu-item>
            <el-menu-item index="role">
              <i class="el-icon-s-tools"></i>
              <span>角色管理</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>消息管理</span>
            </template>

            <el-menu-item index="messages">
              <i class="el-icon-s-tools"></i>
              <span>平台消息</span>
            </el-menu-item>

            <el-menu-item index="newmessages">
              <i class="el-icon-s-tools"></i>
              <span>发布新消息</span>
            </el-menu-item>

          </el-submenu>

          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>系统管理</span>
            </template>

            <el-menu-item index="aboutus">
              <i class="el-icon-s-tools"></i>
              <span>关于我们</span>
            </el-menu-item>

            <el-menu-item index="contactus">
              <i class="el-icon-s-tools"></i>
              <span>联系我们</span>
            </el-menu-item>

            <el-menu-item index="feedbacks">
              <i class="el-icon-s-tools"></i>
              <span>意见反馈</span>
            </el-menu-item>
            <!-- <el-menu-item index="feedtypes">
              <i class="el-icon-s-tools"></i>
              <span>意见类型</span>
            </el-menu-item> -->

            <el-menu-item index="issues">
              <i class="el-icon-s-tools"></i>
              <span>常见问题</span>
            </el-menu-item>

            <el-menu-item index="ini">
              <i class="el-icon-s-tools"></i>
              <span>启动页图片</span>
            </el-menu-item>

            
          </el-submenu>

          <el-submenu index="5">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>标签管理</span>
            </template>
            <el-menu-item index="labels">
              <i class="el-icon-s-tools"></i>
              <span>标签列表</span>
            </el-menu-item>
            <el-menu-item index="labels-map">
              <i class="el-icon-s-tools"></i>
              <span>标签列表-地图</span>
            </el-menu-item>
            <!-- <el-menu-item index="addlabels">
              <i class="el-icon-s-tools"></i>
              <span>新增标签</span>
            </el-menu-item> -->
          </el-submenu>
          
          <el-submenu index="6">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>统计分析</span>
            </template>

             <el-menu-item index="statistic">
              <i class="el-icon-s-tools"></i>
              <span>用户数据统计</span>
                </el-menu-item>

             <el-menu-item index="score">
              <i class="el-icon-s-tools"></i>
              <span>综合评分</span>
             </el-menu-item>

             <el-menu-item index="form">
              <i class="el-icon-s-tools"></i>
              <span>评分表格</span>
             </el-menu-item>

          </el-submenu>

          <el-submenu index="7">

              <template slot="title">
               <i class="el-icon-menu"></i>
              <span>参数管理</span>
              </template>

               <el-menu-item index="params">
              <i class="el-icon-s-tools"></i>
              <span>等级年龄速度参数</span>
                </el-menu-item>

              <el-menu-item index="scoreparams">
              <i class="el-icon-s-tools"></i>
              <span>评分参数</span>
                </el-menu-item>

                <el-menu-item index="accparams">
              <i class="el-icon-s-tools"></i>
              <span>急加速参数</span>
                </el-menu-item>

                  <el-menu-item index="staparams">
              <i class="el-icon-s-tools"></i>
              <span>平顺度参数</span>
                </el-menu-item>

                <el-menu-item index="roadparams">
              <i class="el-icon-s-tools"></i>
              <span>路面铺装参数</span>
                </el-menu-item>

                <el-menu-item index="turnparams">
              <i class="el-icon-s-tools"></i>
              <span>急转弯参数</span>
                </el-menu-item>

          </el-submenu>

        </el-menu>
      </el-aside>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    edit() {
      this.$router.push({
        path: 'own',
        query: {
          name: 'id',
          code: this.admin.id,
        },
      })
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
    handleCommand(command) {
      if (command === 'logout') {
        this.logout()
      }
      if (command === 'edit') {
        this.edit()
      }
    },
    getAccount() {
      this.account = window.sessionStorage.getItem('account')
    },
    async getAdmin() {
      const { data: res } = await this.$http.get(
        'admin/account/query/' + this.account
      )
      if (res.code !== 200) return this.$message.error('Error:' + res.message)
      this.admin = res.data
      console.log(this.admin)
    },
  },
  data() {
    return {
      isCollapse: false,
      activePath: '',
      account: null,
      admin: {},
    }
  },
  created() {
    this.getAccount()
    this.getAdmin()
  },
}
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.iconfont {
  margin: 10px;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.w-font {
  font-size: 10px;
}

.f-right {
  margin-right: 35px;
}
</style>
